var core = require('core');

var error = function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  if(req.originalUrl.indexOf(core.config.viewPath) === 0)
    res.render("error");
  else if(req.originalUrl.indexOf(core.config.apiPath) === 0)
    res.json({code: err.status || 500, msg: err.message});
  else res.render("error");
};

error[404] = require("./404")

module.exports = error;
